import $store from '@/store/index.js';
import msgSqlite from "@/sqlite_services/msg.js"
//撤回消息
const handle = async(data)=>{
	try{
		let msgsql = await $store.state.user.sqlite.message.where([{
				field: 'msg_id',
				val: `'${data.msg_id}'`
			},
			{
				field: 'chat_type',
				val: `'${data.chat_type}'`,
				logic: 'AND'
			}
		]).first()
		if(msgsql){
			msgSqlite.delMsg(data.msg_id,data.chat_type)
			//通知页面删除
			//发送者的id
			let myid = $store.state.user.user_info.user_id
			let chat_id = data.sender_id == myid ? data.target_id : data.sender_id
			if(data.chat_type == 'group'){
				chat_id = data.target_id
			}
			const activeChatUuid = $store.state.chat.chatInfo && $store.state.chat.chatInfo.uuid || ''; // 访问根级状态的chatInfo
			if(chat_id == activeChatUuid){
				uni.$emit('onMessageControls', {
					type:'withdraw',
					data
				})
			}
		}
	}catch(e){
		
	}
}
export default handle